<!--页面组件-->
<template>
  <div>
    <div>
      <CCard class="cdHead">
        <CCardBody class="card-body">
          <div class="cardstyle">
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">任务类型</label>
                <CSelect
                  @change="pushTaskTypeChange($event)"
                  :value.sync="pushTaskType"
                  horizontal
                  :options="taskTypeList"
                  placeholder="请选择"
                  class="input"
                />
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">任务名称</label>
                <CInput
                  v-model="upData.taskName"
                  placeholder="请输入'任务名称'"
                  horizontal
                  class="input"
                />
              </CCol>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">扫描间隔</label>
                <CSelect
                  horizontal
                  :value.sync="upData.crontabExpress"
                  :options="cronList"
                  placeholder="请选择"
                  class="input"
                />
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColScan" style>
                <label class="label">扫描目录</label>
                <CInput
                  v-model="upDataTaskParam.scanDir"
                  placeholder="请输入扫描目录"
                  horizontal
                  class="input"
                />
              </CCol>
              <CCol>
                <CButton
                  color="info"
                  size="sm"
                  @click="selectPushTaskScanDir('scanDir')"
                  class="btnSelectScanDir"
                  >...</CButton
                >
              </CCol>
              <CCol sm="6" class="myColPro" style>
                <label class="label">生产目录</label>
                <CInput
                  v-model="upDataTaskParam.proDir"
                  placeholder="请输入生产目录"
                  horizontal
                  class="input"
                />
              </CCol>
              <CCol>
                <CButton
                  color="info"
                  size="sm"
                  @click="selectPushTaskProDir('proDir')"
                  class="btnSelectProDir"
                  >...</CButton
                >
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">组织机构</label>
                <CSelect
                  horizontal
                  :value.sync="upDataTaskParam.enterId"
                  :options="enterpriseList"
                  placeholder="请选择"
                  @change="selectEnterprise($event)"
                  class="input"
                />
              </CCol>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">用户部门</label>
                <CSelect
                  horizontal
                  :value.sync="upDataTaskParam.orgId"
                  :options="organizationList"
                  placeholder="请选择"
                  @change="selectOrganization($event)"
                  class="input"
                />
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">用户名</label>
                <CSelect
                  horizontal
                  :value.sync="upDataTaskParam.userId"
                  :options="userNameList"
                  placeholder="请选择"
                  @change="selectUserName($event)"
                  class="input"
                />
              </CCol>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">文件类型</label>
                <CSelect
                  horizontal
                  :options="fileTypeList"
                  :value.sync="upDataTaskParam.finishFlag"
                  placeholder="请选择文件类型"
                  @change="selectFileType($event)"
                  class="input"
                />
              </CCol>
            </CRow>
          </div>
          <!-- </CCardBody>  -->
          <table v-if="0" class="table0">
            <tbody class="table-border">
              <tr>
                <td>
                  <div class="position-relative table-responsive1">
                    <table class="table table-hover">
                      <tbody>
                        <tr v-show="showGlobalParameter">
                          <td>
                            <CDataTable
                              :items="globalItems"
                              :fields="fields"
                              class="paramTable globalTag"
                              :header="haveHeader"
                              border
                              hover
                            >
                              <template #value="{ item }" style="width: 60%">
                                <td>
                                  <CSelect
                                    v-if="
                                      item.type.name.toLowerCase() === 'select'
                                    "
                                    horizontal
                                    :options="item.constraint"
                                    :value.sync="item.default"
                                    class="inputTd"
                                    placeholder="请选择"
                                  ></CSelect>
                                  <CSelect
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'boolean'
                                    "
                                    horizontal
                                    :options="[
                                      { label: '请选择', value: '' },
                                      { label: '是', value: true },
                                      { label: '否', value: false },
                                    ]"
                                    :value.sync="item.default"
                                    class="inputTd"
                                  ></CSelect>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'dir'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'file'
                                    "
                                  >
                                    <template horizontal>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() ===
                                      'spatialref'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserRef(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'float'
                                    "
                                    class="inputTd"
                                  >
                                    <Form
                                      :model="item"
                                      :rules="ruleCustom"
                                      ref="item"
                                    >
                                      <FormItem
                                        prop="default"
                                        :rules="[
                                          {
                                            validator: (
                                              rule,
                                              value,
                                              callback
                                            ) => {
                                              let data = item;
                                              if (
                                                !data.hasOwnProperty(
                                                  'constraint'
                                                )
                                              )
                                                callback();
                                              let min = data.constraint.min;
                                              let max = data.constraint.max;
                                              let num = parseFloat(value);
                                              var reg = /-?[0-9]*\.?[0-9]+/;
                                              if (
                                                new RegExp(reg).test(value) ==
                                                false
                                              ) {
                                                if (max == undefined) {
                                                  callback(
                                                    '请输入' + min + '以上的值'
                                                  );
                                                } else
                                                  callback(
                                                    '请输入' +
                                                      min +
                                                      '-' +
                                                      max +
                                                      '之间的值'
                                                  );
                                              } else {
                                                if (max == undefined) {
                                                  if (num >= min) callback();
                                                  else
                                                    callback(
                                                      '请输入' +
                                                        min +
                                                        '以上的值'
                                                    );
                                                } else {
                                                  if (num >= min && num <= max)
                                                    callback();
                                                  else {
                                                    if (max == undefined)
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '以上的值'
                                                      );
                                                    else
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '-' +
                                                          max +
                                                          '之间的值'
                                                      );
                                                  }
                                                }
                                              }
                                            },
                                          },
                                        ]"
                                      >
                                        <Input
                                          v-model="item.default"
                                          clearable
                                          autocomplete="off"
                                          placeholder="请输入浮点数"
                                        />
                                      </FormItem>
                                    </Form>
                                  </div>
                                  <CInput
                                    v-else
                                    v-model="item.default"
                                    clearable
                                    class="inputTd"
                                  />
                                </td>
                              </template>
                            </CDataTable>
                          </td>
                        </tr>
                        <tr
                          v-for="(item2, index) in items"
                          :key="index"
                          v-show="showInputParameter"
                        >
                          <td>
                            <CDataTable
                              :items="item2"
                              :fields="fields"
                              class="paramTable inputTag"
                              :header="haveHeader"
                              border
                              hover
                            >
                              <template #value="{ item }" style="width: 60%">
                                <td>
                                  <CSelect
                                    v-if="
                                      item.type.name.toLowerCase() === 'select'
                                    "
                                    horizontal
                                    :options="item.constraint"
                                    :value.sync="item.default"
                                    class="inputTd"
                                    placeholder="请选择"
                                  ></CSelect>
                                  <CSelect
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'boolean'
                                    "
                                    horizontal
                                    :options="[
                                      { label: '请选择', value: '' },
                                      { label: '是', value: true },
                                      { label: '否', value: false },
                                    ]"
                                    :value.sync="item.default"
                                    class="inputTd"
                                  ></CSelect>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'dir'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'file'
                                    "
                                  >
                                    <template horizontal>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() ===
                                      'spatialref'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserRef(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'float'
                                    "
                                    class="inputTd"
                                  >
                                    <Form
                                      :model="item"
                                      :rules="ruleCustom"
                                      ref="item"
                                    >
                                      <FormItem
                                        prop="default"
                                        :rules="[
                                          {
                                            validator: (
                                              rule,
                                              value,
                                              callback
                                            ) => {
                                              let data = item;
                                              if (
                                                !data.hasOwnProperty(
                                                  'constraint'
                                                )
                                              )
                                                callback();
                                              let min = data.constraint.min;
                                              let max = data.constraint.max;
                                              let num = parseFloat(value);
                                              var reg = /-?[0-9]*\.?[0-9]+/;
                                              if (
                                                new RegExp(reg).test(value) ==
                                                false
                                              ) {
                                                if (max == undefined) {
                                                  callback(
                                                    '请输入' + min + '以上的值'
                                                  );
                                                } else
                                                  callback(
                                                    '请输入' +
                                                      min +
                                                      '-' +
                                                      max +
                                                      '之间的值'
                                                  );
                                              } else {
                                                if (max == undefined) {
                                                  if (num >= min) callback();
                                                  else
                                                    callback(
                                                      '请输入' +
                                                        min +
                                                        '以上的值'
                                                    );
                                                } else {
                                                  if (num >= min && num <= max)
                                                    callback();
                                                  else {
                                                    if (max == undefined)
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '以上的值'
                                                      );
                                                    else
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '-' +
                                                          max +
                                                          '之间的值'
                                                      );
                                                  }
                                                }
                                              }
                                            },
                                          },
                                        ]"
                                      >
                                        <Input
                                          v-model="item.default"
                                          clearable
                                          autocomplete="off"
                                          placeholder="请输入浮点数"
                                        />
                                      </FormItem>
                                    </Form>
                                  </div>
                                  <CInput
                                    v-else
                                    v-model="item.default"
                                    clearable
                                    class="inputTd"
                                  />
                                </td>
                              </template>
                            </CDataTable>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
          <!-- <CCardFooter>
            <CButton type="submit" size="sm" color="info" @click="save">更新</CButton>
          </CCardFooter>-->
        </CCardBody>
      </CCard>
    </div>
    <CModal
      title="选择目录"
      color="info"
      :show.sync="showZtreeModal"
      :closeOnBackdrop="false"
      size="lg"
      centered
    >
      <div style="height: 60px">
        <div>
          <CLink class="px-2" @click="shareMenu(currenItem)">共享文件夹</CLink>
          <br />
          <CLink class="px-2" @click="userMenu(currenItem)">用户文件夹</CLink>
          <!-- <br>
          <CLink class="px-2" >数据订单</CLink>-->
        </div>
        <div class="optiostyle displaySuffix" style="display: none">
          <CInputCheckbox
            label="是否批量"
            type="radio"
            :checked.sync="isBatch"
            value="是否批量"
          />
          <CSelect
            label="过滤条件"
            horizontal
            :options="suffix"
            :value.sync="currenSelectSuffix"
            class="selectSuffix"
          ></CSelect>
          <CButton color="info" @click="suffixSearch" class="suffixBtn"
            >过滤</CButton
          >
        </div>
      </div>
      <div class="treeDiv">
        <ul id="treeDemo" class="ztree"></ul>
      </div>

      <template #header>
        <h5>选择目录</h5>
        <CButtonClose @click="menuCancel" />
      </template>
      <template #footer>
        <CButton @click="menuSaveAs" color="info">另存为</CButton>
        <CButton @click="menuOk" color="info">确定</CButton>
        <CButton @click="menuCancel" color="light ">取消</CButton>
      </template>
    </CModal>
    <CModal
      title="推送任务选择目录"
      color="info"
      :show.sync="showPushTaskZtreeModal"
      :closeOnBackdrop="false"
      size="lg"
      centered
    >
      <div class="treeDiv">
        <ul id="pushTaskTree2" class="ztree"></ul>
      </div>

      <template #header>
        <h5>选择目录</h5>
        <CButtonClose @click="pushTaskMenuCancel" />
      </template>
      <template #footer>
        <CButton @click="pushTaskMenuOk" color="info">确定</CButton>
        <CButton @click="pushTaskMenuCancel" color="light">取消</CButton>
      </template>
    </CModal>
  </div>
</template>
<script>
const fields = [
  // {
  //   label: "序号",
  //   key: "number",
  //   _style: "width:3%;text-align: center;background:rgba(241,244,249,1);",
  //   align: "center"
  // },
  // {
  //   label: "分组",
  //   key: "groupName",
  //   _style: "width:25%;text-align: center;background:rgba(241,244,249,1);",
  //   align: "center"
  // },
  // {
  //   label: "名称",
  //   key: "name",
  //   _style: "width:25%;text-align: center;background:rgba(241,244,249,1);",
  //   align: "center"
  // },
  {
    label: "参数类型",
    key: "label",
    _style: "width:25%;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  // {
  //   label: "描述",
  //   key: "desc",
  //   _style: "width:10%;text-align: center;background:rgba(241,244,249,1);",
  //   align: "center"
  // },

  {
    key: "value",
    label: "参数值",
    _style: "width:30%;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
];
export default {
  name: "updateTask",
  data() {
    var validateuser = function (rule, value, callback) {
      if (!value) {
        return callback(new Error("请输入用户名"));
      } else if (!/^[a-zA-Z\d]+$/.test(value)) {
        return callback(new Error("请正确输入用户名"));
      } else {
        callback();
      }
    };
    var validateAge = (rule, value, callback) => {
      if (!Number.isInteger(+value)) {
        callback(new Error("请输入数字"));
      } else {
        callback();
      }
    };
    var validateCount = (rule, value, callback) => {
      if (!Number.isInteger(+value)) {
        callback(new Error("请输入数字"));
      } else if (Number.isInteger(+value)) {
        let num = Number(value);
        let length = value.length;
        if (length < 3) {
          callback(new Error("请输入长度为3的数字"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      fields,
      showInputParameter: true,
      showGlobalParameter: true,
      data: [],
      sate: "",
      id: -1,
      sensor: "",
      flowId: "",
      sateList: [
        {
          value: "GF1",
          label: "GF1",
        },
        {
          value: "GF2",
          label: "GF2",
        },
        {
          value: "ZY3",
          label: "ZY3",
        },
      ],
      sersorList: [
        {
          value: "PMS",
          label: "PMS",
        },
        {
          value: "WFV",
          label: "WFV",
        },
      ],
      cronList: [],
      ruleCustom: {
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" },
          { validator: validateAge, trigger: "blur" },
        ],
        count: [
          { required: true, message: "数量不能为空", trigger: "blur" },
          { validator: validateCount, trigger: "blur" },
        ],
        default: [
          { required: true, message: "请输入数字", trigger: "blur" },
          { validator: validateCount, trigger: "blur" },
        ],
      },
      pushTaskType: "RoutineTask",
      bIsScanDir: true,
      taskTypeList: [
        {
          value: "EmergencyTask",
          label: "应急任务",
        },
        {
          value: "RoutineTask",
          label: "常规任务",
        },
        {
          value: "ModisTask",
          label: "MODIS任务",
        },
      ],
      typeList: [],
      items: [],
      globalItems: [],
      upData: {
        crontabExpress: "",
        flowId: "",
        sourceId: 1,
        taskName: "",
        taskParameter: "",
      },
      upDataTaskParam: {
        scanDir: "",
        proDir: "",
        finishFlag: "",
        taskOwner: "", //任务发起者
        department: "", //发起者部门
        enterId: -1, //组织机构
        orgId: -1, //部门
        userId: -1, //用户
      },
      fileTypeList: [".gz", ".zip"],
      enterpriseList: [],
      organizationList: [],
      userNameList: [],
      showPushTaskZtreeModal: false,
      showZtreeModal: false,
      isBatch: false,
      suffix: [],
      currenSelectSuffix: "",
      haveHeader: false,
    };
  },
  watch: {
    groupName(newVal, oldVal) {
      if (newVal.length >= 50) {
        this.$Message.warning("任务名称长度不得超过50个字符");
      }
    },
    flowId(newVal, oldVal) {
      this.upData.flowId = newVal;
      this.getParam(newVal);
    },
  },
  mounted() {
    this.getProduct();
    this.source();
    this.getCronList();
    this.getEnterpriseList();
  },
  methods: {
    selectFileType(event) {
      this.upDataTaskParam.finishFlag = event.target.value;
    },
    source() {
      let self = this;
      let path = this.$api.processingApi.source;
      this.http.get(path).then((res) => {
        if (res.data.code == 0) {
          self.upData.sourceId = res.data.data.id;
        } else {
          console.log("查询sourceid错误");
        }
      });
    },
    pushTaskTypeChange(event) {
      let self = this;
      let typeValue = event.target.value;
      self.pushTaskType = typeValue;
    },
    // 应急推送任务扫描目录选择
    selectPushTaskScanDir(type) {
      this.bIsScanDir = true;
      this.showPushTaskZtreeModal = true;
      this.pushTaskMenu(type);
    },
    // 应急推送任务生产目录选择
    selectPushTaskProDir(type) {
      this.bIsScanDir = false;
      this.showPushTaskZtreeModal = true;
      this.pushTaskMenu(type);
    },
    pushTaskMenu(type) {
      let treeObj = $.fn.zTree.getZTreeObj("pushTaskTree2");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }

      let path; //1为共享文件夹,2为用户文件夹,3为紧急推送扫描文件夹,4为应急任务生产根目录,5为常规推送生产根目录,6为自动推送Modis生产根目录,7为自动推送Modis扫描根目录
      if (type == "scanDir") {
        if (this.pushTaskType == "EmergencyTask") {
          path = this.$api.processingApi.fileRootPath + 3;
        } else if (this.pushTaskType == "RoutineTask") {
          path = this.$api.processingApi.fileRootPath + 1;
        } else if (this.pushTaskType == "ModisTask") {
          path = this.$api.processingApi.fileRootPath + 7;
        } else {
          path = this.$api.processingApi.fileRootPath + 1;
        }
      } else {
        if (this.pushTaskType == "EmergencyTask") {
          path = this.$api.processingApi.fileRootPath + 4;
        } else if (this.pushTaskType == "RoutineTask") {
          path = this.$api.processingApi.fileRootPath + 5;
        } else if (this.pushTaskType == "ModisTask") {
          path = this.$api.processingApi.fileRootPath + 6;
        } else {
          path = this.$api.processingApi.fileRootPath + 1;
        }
      }
      this.pushTaskMenuSetting(path);
    },
    // 应急推送任务扫描目录、生产目录Ztree设置
    pushTaskMenuSetting(urlPath) {
      let checkType = { Y: "", N: "" }; //父与子的关联去掉
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: checkType,
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          beforeClick: this.beforeClick,
          onClick: this.zTreeOnClick,
          onCheck: this.zTreePushTaskOnCheck,
          onExpand: this.zTreeOnClick,
        },
      };

      this.http.get(urlPath).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#pushTaskTree2"), setting, data.data);
        }
      });
    },
    zTreePushTaskOnCheck(event, treeId, treeNode) {
      var treeObj = $.fn.zTree.getZTreeObj(treeId),
        nodes = treeObj.getCheckedNodes(true);

      if (!treeNode.isParent) {
        this.$Message.warning("请选择文件夹！");
        treeNode.checked = false;
        treeObj.updateNode(treeNode);
        return;
      }
      if (!this.bIsScanDir && nodes.length > 1) {
        //限制单个文件夹
        this.$Message.warning("生产目录只能选择一个文件夹！");
        treeNode.checked = false;
        treeObj.updateNode(treeNode);
        return;
      }
    },
    pushTaskMenuOk() {
      let treeObj = $.fn.zTree.getZTreeObj("pushTaskTree2"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (var index in nodes) {
        tempNode = nodes[index];
        if (info == "") {
          info = tempNode.id;
        } else {
          info += ";" + tempNode.id;
        }
      }

      if (this.bIsScanDir) {
        this.upDataTaskParam.scanDir = info;
      } else {
        this.upDataTaskParam.proDir = info;
      }

      this.pushTaskReset();
    },
    pushTaskMenuCancel() {
      this.pushTaskReset();
    },
    pushTaskReset() {
      var treeObj;
      this.showPushTaskZtreeModal = false;
      treeObj = $.fn.zTree.getZTreeObj("pushTaskTree2");
      if (treeObj == null) return;

      var nodes = treeObj.getNodes();
      for (var i = nodes.length - 1; i >= 0; i--) {
        treeObj.removeNode(nodes[i]);
      }
    },
    //////////////////////////////////以下为目录浏览功能//////////////////////////////////
    //文件浏览功能
    browserFile(item) {
      let self = this;
      self.currenItem = item;
      this.showZtreeModal = true;
      this.isRefModal = false;

      if (!item.hasOwnProperty("constraint")) {
        self.suffix = [];
        self.currenSelectSuffix = "";
        return;
      }
      let extensions = item.constraint.extensions.split(/[,;]/);
      let tempSuffix = [];
      for (var i in extensions) {
        let newObj = new Object();
        let name = extensions[i];
        newObj.value = name.substring(2, name.length);
        newObj.label = name.substring(2, name.length);
        tempSuffix.push(newObj);
      }
      self.suffix = tempSuffix;
      self.currenSelectSuffix = tempSuffix[0].value;
    },

    browserRef(item) {
      this.isRefModal = true;
      this.showZtreeRefModal = true;
      let self = this;
      self.currenItem = item;
      let path = this.$api.processingApi.browserRefPath;
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: { Y: "", N: "" },
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          // beforeClick: this.beforeClick,
          // onClick: this.zTreeOnClick,
          // onCheck: this.zTreeOnCheck,
          // onExpand: this.zTreeOnClick
        },
      };
      this.http.get(path).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#treeDemo1"), setting, data.data);
          console.log("refTree", data.data);
        }
      });
    },

    menuSetting(item, urlPath) {
      $(".displaySuffix").css("display", "block");
      let checkType = { Y: "", N: "" }; //父与子的关联去掉
      if (item.type.name.toLowerCase() === "file") {
        checkType = { Y: "s", N: "ps" };
      }
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: checkType,
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          beforeClick: this.beforeClick,
          onClick: this.zTreeOnClick,
          onCheck: this.zTreeOnCheck,
          onExpand: this.zTreeOnClick,
        },
      };

      this.http.get(urlPath).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#treeDemo"), setting, data.data);
        }
      });
    },
    shareMenu(item) {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }
      let path = this.$api.processingApi.fileRootPath + 1; //1 共享 2 用户
      this.menuSetting(item, path);
    },

    userMenu(item) {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }
      let path = this.$api.processingApi.fileRootPath + 2; //1 共享 2 用户
      this.menuSetting(item, path);
    },

    zTreeOnClick(event, treeId, treeNode) {
      let path = this.$api.processingApi.getFileListByPath;
      let param = {
        path: treeNode.id,
      };
      var treeObj = $.fn.zTree.getZTreeObj(treeId);
      var node = treeObj.getNodeByParam("id", treeNode.id);
      treeObj.selectNode(node);
      let sNode = treeObj.getSelectedNodes();
      if (sNode.length > 0) {
        let zAsync = sNode[0].zAsync;
        treeObj.reAsyncChildNodes(treeNode, "refresh");
        if (zAsync) {
        } else {
          this.http.get(path, param).then((res) => {
            let data = res.data;
            if (data.success == true) {
              treeNode.halfCheck = false;
              treeObj.addNodes(treeNode, data.data, false);
              sNode[0].zAsync = true;
            }
          });
        }
      }
    },

    zTreeOnCheck(event, treeId, treeNode) {
      var treeObj = $.fn.zTree.getZTreeObj(treeId),
        nodes = treeObj.getCheckedNodes(true);
      let item = this.currenItem;

      if (item.type.name.toLowerCase() === "file") {
        //文件筛选过滤
        // if (!item.type.plural && nodes.length > 1) {
        //   //限制单个文件
        //   this.$Message.error("该文件路径限制只能选一个文件哦！");
        //   treeNode.checked = false;
        //   treeObj.updateNode(treeNode);
        //   return;
        // }
        this.getFile(treeObj, treeNode);
        return;
      }
      if (item.type.name.toLowerCase() === "dir") {
        if (!treeNode.isParent) {
          this.$Message.warning("请选择文件夹！");
          treeNode.checked = false;
          treeObj.updateNode(treeNode);
          return;
        }
        if (!item.type.plural && nodes.length > 1) {
          //限制单个文件夹
          this.$Message.warning("当前算法限制只能选一个文件夹哦！");
          treeNode.checked = false;
          treeObj.updateNode(treeNode);
          return;
        }
      }
    },

    getFile(treeObj, treeNode) {
      let tempNode;
      let childsArr = [];

      if (treeNode.hasOwnProperty("children") && treeNode.checked) {
        tempNode = treeNode.children;
        this.getChildsByTreeNode(treeNode, childsArr);
        this.getFileBySuffix(treeObj, childsArr);
      } else if (treeNode.checked) {
        let suffix = this.currenSelectSuffix;
        let fileName = treeNode.name.toLowerCase();
        let regValue = fileName.substring(
          fileName.length - suffix.length,
          fileName.length
        );
        if (
          !suffix.hasOwnProperty("value") &&
          regValue !== suffix.toLowerCase()
        ) {
          treeNode.checked = false;
          this.$Message.warning("文件格式不符合过滤条件");
        }
        treeObj.updateNode(treeNode);
      }
    },

    getChildsByTreeNode(treeNode, childsArr) {
      if (treeNode.isParent) {
        //是父节点获取所有子节点
        let childs = treeNode.children;
        for (var i in childs) {
          childsArr.push(childs[i]);
          this.getChildsByTreeNode(childs[i], childsArr);
        }
      }
      return childsArr;
    },
    getFileBySuffix(treeObj, childsFiles) {
      let nodes = childsFiles;
      let fileName;
      let regValue;
      let tempNode;
      let suffix = this.currenSelectSuffix;
      if (nodes.length == undefined) {
        if (!nodes.isParent) {
          //文件
          fileName = nodes.name.toLowerCase();
          regValue = fileName.substring(
            fileName.length - suffix.length,
            fileName.length
          );
          if (regValue === suffix) nodes.checked = true;
          else nodes.checked = false;
          treeObj.updateNode(nodes);
        }
      }
      for (var i = 0; i < nodes.length; i++) {
        tempNode = nodes[i];
        this.getFileBySuffix(treeObj, tempNode);
        if (tempNode.isParent) {
          let tempChilds = tempNode.children;
          let num = 0;
          for (var m in tempChilds) {
            if (tempChilds[m].checked) num++;
            if (num > 1) break;
          }
          if (num < 1) {
            tempNode.checked = false;
            treeObj.updateNode(tempNode);
          }
        }
      }
    },

    menuOk() {
      let isBatch = this.isBatch;
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (var index in nodes) {
        tempNode = nodes[index];
        if (
          this.currenItem.type.name.toLowerCase() === "file" &&
          tempNode.isParent
        )
          continue;
        if (info == "") info = tempNode.id;
        else if (isBatch) {
          info += "#HT#" + tempNode.id;
        } else {
          info += "#TASK#" + tempNode.id;
        }
      }

      console.log("zuobio之前的参考" + info);
      this.currenItem.default = info;
      this.reset();
    },
    menuRefOk() {
      let isBisRefModalatch = this.isRefModal;
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo1"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (let i in nodes) {
        if (nodes.length > 1) {
          this.$Message.warning("请选择一个参考坐标系");
          break;
        }
        info = nodes[0].content;
        console.log("之前的参考" + info);
        info = info.replace(/[\r\n]/g, "");
        console.log("之后的参考" + info);
        this.currenItem.default = info; //nodes[0].name;
        this.reset();
      }
    },
    menuCancel() {
      this.reset();
    },

    //目录选择页面 重置
    reset() {
      let isRefModal = this.isRefModal;
      var treeObj;
      if (isRefModal) {
        this.showZtreeRefModal = false;
        treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
      } else {
        this.showZtreeModal = false;
        $(".displaySuffix").css("display", "none");
        treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      }

      if (treeObj == null) return;
      var nodes = treeObj.getNodes();
      for (var i = nodes.length - 1; i >= 0; i--) {
        treeObj.removeNode(nodes[i]);
      }
    },

    // 过滤条件搜索
    suffixSearch() {
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = treeObj.getCheckedNodes(true);
      if (nodes.length < 1) {
        this.$Message.warning("没有选中的文件或文件夹");
        return;
      }
      for (var i in nodes) {
        this.getFile(treeObj, nodes[i]);
      }
    },

    // 文件另存为modal界面初始化
    menuSaveAs() {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (!treeObj) {
        this.$Message.warning("请选择文件夹！");
        return;
      }

      let selectNodes = treeObj.getSelectedNodes();
      if (selectNodes.length < 1) {
        this.$Message.warning("请选择文件夹节点！");
        return;
      }
      if (!selectNodes[0].isParent) {
        this.$Message.warning("请选择文件夹！");
        return;
      }
      this.newFileName = ""; //界面文件名置为空
      this.saveAsModal = true;

      if (this.currenItem.type.name.toLowerCase() === "file") {
        self.isFile = true;
        $(".saveFile").css("display", "block");
        $(".saveFolder").css("display", "none");
      }
      //用于新增文件或文件夹标识
      else {
        $(".saveFile").css("display", "none");
        $(".saveFolder").css("display", "block");
        self.isFile = false;
      }
    },

    saveAsFileOK() {
      let fileName = this.newFileName;
      this.saveAsModal = false;
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      let selectNodes = treeObj.getSelectedNodes();
      let newNode = "";
      if (!fileName) {
        this.$Message.warning("文件名或文件夹名称为空，请重写填写");
      }
      if (isFile) {
        //文件 判断文件名是否符合带后缀
        let a = fileName.split("").reverse().join("");
        let b = a.substring(0, a.search(/\./)).split("").reverse().join("");
        if (b == null || b == "") {
          this.$Message.warning("该文件名无效，没有后缀");
          return;
        }
        newNode = {
          name: fileName,
          id: selectNodes[0].id + "/" + fileName,
          isParent: false,
        };
      } else
        newNode = {
          name: fileName,
          id: selectNodes[0].id + "/" + fileName,
          isParent: true,
        };
      if (newNode == null) return;
      treeObj.addNodes(selectNodes[0], 0, newNode, true); //新增节点放在文件夹的顶层并默认选择
      let node = selectNodes[0].children[0];
      node.checked = true;
      treeObj.updateNode(node);
    },

    saveAsFileCancel() {
      this.saveAsModal = false;
    },
    //////////////////////////////////以上文件浏览功能//////////////////////////////////

    goBack() {
      this.$router.go(-1);
    },
    getProduct() {
      let self = this;
      let path = this.$api.processingApi.search;
      let param = {
        groupId: 2,
      };
      this.http.get(path, param).then((res) => {
        if (res.data.code == 0) {
          for (let i = 0; i < res.data.data.length; i++) {
            let param = {
              value: res.data.data[i].id,
              label: res.data.data[i].workflowName,
            };
            self.typeList.push(param);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    getParam(val) {
      let self = this;
      let path = this.$api.processingApi.getParam;
      let param = {
        workFlowId: val,
      };
      this.http.get(path, param).then((res) => {
        let data = res.data;
        if (res.data.code == 0) {
          let inputParam = JSON.parse(data.data.processParameters).inputParam;
          let globalParam = JSON.parse(data.data.processParameters).globalParam;
          let params = JSON.parse(data.data.processParameters);

          this.showInputParameter = true;
          if (
            params.globalParam == undefined ||
            params.globalParam.length < 1
          ) {
            this.showInputParameter = true;
            this.showGlobalParameter = false;
            this.items = inputParam;
            this.globalItems = null;
          } else {
            this.showInputParameter = false;
            this.showGlobalParameter = true;
            this.items = inputParam;
            this.globalItems = globalParam;
            console.log("全局参数" + globalParam);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    getAuto(id) {
      let self = this;
      self.data = [];
      let pageSize = 10;
      let path = this.$api.processingApi.autoTaskQuery + "/" + id;
      this.http.get(path).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          self.upData = res.data.data;
          if (
            self.upData.taskParameter != null &&
            self.upData.taskParameter != "" &&
            self.upData.taskParameter != "undefined"
          ) {
            self.upDataTaskParam = JSON.parse(self.upData.taskParameter);
            self.upDataTaskParam.enterId = parseInt(
              self.upDataTaskParam.enterId
            );
            self.upDataTaskParam.orgId = parseInt(self.upDataTaskParam.orgId);
            self.upDataTaskParam.userId = parseInt(self.upDataTaskParam.userId);

            self.getOrganizationList(self.curEnterId);
            self.getUserNameList(self.curOrgId);
          }

          if (self.upData.sourceId == 1) {
            self.pushTaskType = "EmergencyTask";
          } else if (self.upData.sourceId == 2) {
            self.pushTaskType = "RoutineTask";
          } else if (self.upData.sourceId == 3) {
            self.pushTaskType = "ModisTask";
          } else {
            this.$Message.warning("不能识别的任务类型！");
          }

          for (let i = 0; i < self.data.length; i++) {
            self.data[i].number = i + 1;
          }

          // console.log(JSON.stringify(self.upData));
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    save(updId) {
      let self = this;
      self.data = [];
      let path = this.$api.processingApi.update + "/" + updId;

      self.upData.taskParameter = JSON.stringify(self.upDataTaskParam);

      if (this.pushTaskType == "EmergencyTask") {
        self.upData.sourceId = 1;
      } else if (this.pushTaskType == "RoutineTask") {
        self.upData.sourceId = 2;
      } else if (this.pushTaskType == "ModisTask") {
        self.upData.sourceId = 3;
      } else {
        self.upData.sourceId = "";
      }

      let param = this.upData;
      this.http.post(path, param).then((res) => {
        if (res.data.success) {
          //self.saveDefault();
          this.$emit("closeupdateTask", false);
          this.$Message.success("更新成功");
        } else {
          this.$Message.error(res.data.message);
        }
        self.isShow = false;
      });
    },
    saveDefault() {
      let self = this;
      self.data = [];
      let path = this.$api.processingApi.updateDefalut;
      let defaultParam = { inputParam: [] };
      defaultParam.globalParam = this.globalItems;
      for (var i in inputParamData)
        defaultParam.inputParam.push(inputParamData[i]);
      let param = {
        processParameters: JSON.stringify(defaultParam),
        workFlowId: self.flowId,
      };

      this.http.post(path, param).then((res) => {
        if (res.data.success) {
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },

    getCronList() {
      let path = this.$api.processingApi.getAllChildByDictCode;
      let param = {
        dictCode: "cron",
      };
      this.http.get(path, param).then((res) => {
        if (res.data.code == 0) {
          let dictCodeList = res.data.data.dictCodeList;
          this.cronList.push({ label: "请选择", value: "" });
          for (let dictCode of dictCodeList) {
            let cron = {
              label: dictCode.dictName,
              value: dictCode.dictCode,
            };
            this.cronList.push(cron);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    getEnterpriseList() {
      let self = this;
      self.enterpriseList = [];
      let path = self.$api.processingApi.getTree;
      let param = {
        isTree: false,
      };
      this.http.get(path, param).then((res) => {
        if (res.data.success) {
          let content = res.data.data;
          for (let i = 0; i < content.length; i++) {
            let enterprise = {
              value: content[i].id,
              label: content[i].name,
            };
            self.enterpriseList.push(enterprise);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectEnterprise($event) {
      let self = this;

      self.upDataTaskParam.enterId = paeseInt(event.target.value);
      self.getOrganizationList(self.upDataTaskParam.enterId);
    },
    getOrganizationList(enterpriseId) {
      let self = this;
      debugger;
      self.organizationList = [];
      let path = this.$api.processingApi.organization;
      let param = {
        enterId: enterpriseId,
        isTree: false,
      };

      this.http.get(path, param).then((res) => {
        if (res.data.success) {
          let content = res.data.data;

          for (let i = 0; i < content.length; i++) {
            let organization = {
              value: content[i].id,
              label: content[i].name,
            };
            self.organizationList.push(organization);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectOrganization($event) {
      let self = this;

      let selectedIndex = event.target.options.selectedIndex;
      let organizationName = event.target.options[selectedIndex].label;

      self.upDataTaskParam.orgId = parseInt(event.target.value);
      self.upDataTaskParam.department = organizationName;
      self.getUserNameList(self.upDataTaskParam.orgId);
    },
    getUserNameList(organizationId) {
      let self = this;
      self.userNameList = [];
      let path = self.$api.processingApi.queryAllUser;
      let param = {
        Authorization: window.sessionStorage.getItem("PIECloud-Token"),
        organizationId: organizationId,
      };

      this.http.get(path, param).then((res) => {
        if (res.data.success) {
          let content = res.data.data;

          for (let i = 0; i < content.userList.length; i++) {
            let userName = {
              value: content.userList[i].id,
              label: content.userList[i].username,
            };
            self.userNameList.push(userName);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectUserName($event) {
      let self = this;

      let selectedIndex = event.target.options.selectedIndex;
      let userName = event.target.options[selectedIndex].label;

      self.upDataTaskParam.userId = parseInt(event.target.value);
      self.upDataTaskParam.taskOwner = userName;
    },
  },
};
</script>
<style scoped>
.myCol {
  margin-left: 10px;
  display: flex;
  align-items: center;
}
.myColPri {
  width: 13%;
  margin-right: 10px;
}
.myCol1 {
  width: 90px;
  margin-left: 0px;
}
.myColtemp {
  display: flex;
  align-items: center;
}
.myColScan {
  display: flex;
  align-items: center;
}
.myColPro {
  display: flex;
  align-items: center;
  margin-left: -100px;
  left: 50px;
}
.search {
  display: flex;
}
.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.76563rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  width: 50px;
}
.table-responsive {
  height: 50% !important;
}
.label {
  width: 80px;
  margin-right: 20px;
  margin-bottom: 0px;
}
.m_radio_group {
  height: 21px;
  width: 65%;
}
.m_radio_group label {
  margin: 0;
  margin-right: 1%;
}
.btnStyle {
  margin-right: 0px;
}
.strongstyle {
  font-size: 18px;
}
.cardstyle {
  margin-left: 10px;
}

.rowstyle {
  margin-bottom: 20px;
}
.pickstyle {
  width: 50%;
}

.clean {
  margin-left: 10px;
}
.listbtn {
  margin-left: 0px;
}
.deletestyle {
  width: 15px;
  height: 15px;
}
.goBtn {
  margin-right: 10px;
}
.input {
  width: 300px;
}
</style>
<style lang='scss' scoped>
.table0 {
  width: 100%; // 611px;
  // height: 100%;
  table-layout: fixed;
  // background: #d8dbe0;
  background: rgba(216, 216, 216, 0.15);
  // margin-top: 231px;
}
.table0 .table-border {
  border: none;
}
.picDiv {
  width: 310px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  border: 1px solid rgba(217, 217, 217, 1);
  margin: 0.1rem 1rem 0rem 5.6rem;
  //  width: 78%;
  height: 494px;
  display: flex;
  justify-content: center;
  align-items: center;
  .img1 {
    max-width: 100%;
    max-height: 460px;
  }
}
.fileClass {
  float: right;
}
.optiostyle {
  height: 40px;
  width: 370px;
  float: right;
  font-size: 1rem;
  font-weight: bold;
  z-index: 99;
  margin-top: -50px;
}
.saveFileStyle {
  width: 280px;
}
.treeDiv {
  height: 500px;
  width: 760px;
  overflow-y: auto;
}
.treeDiv1 {
  height: 300px;
  width: 300px;
  overflow-y: auto;
}
.suffixBtn {
  margin-left: 10px;
}
.selectSuffix {
  float: left;
  width: 80%;
}
.inputTd {
  float: left;
  width: 69%;
  margin-bottom: 0px;
}
.btnBrowser {
  float: right;
  margin-top: -3px;
  // margin-bottom: 0px;
}
.cardBody {
  margin-top: -21px;
}
/* .table-responsive {
  display: block;
  width: 100%;
  height: 470px;
  overflow-y: auto;
  /* border: 1px solid #c4c9d0; */
/* } */
.batchSelect {
  width: 550px;
  height: 200px;
  overflow-x: auto;
  overflow-y: auto;
}
.inputRadioDiv {
  display: flex;
  flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  width: 570px; //536px;
  margin-left: 102px;
  background: rgba(216, 216, 216, 0.09);
  border-radius: 3px;
  border: 1px solid rgba(151, 151, 151, 0.09);
  margin-top: -18px;
}

.inputRadioDiv1 {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  width: 153px;
  height: calc(1.5em + 0.75rem + 2px);
  margin-left: 108px;
  background: rgba(216, 216, 216, 0.09);
  border-radius: 3px;
  border: 1px solid rgba(151, 151, 151, 0.09);
  padding-top: 6px;
  float: auto;
}
.levelDiv {
  width: 42px;
  float: left;
  padding-top: 6px;
  margin-left: 38px;
}
.inputRadio {
  width: 165px;
  margin-left: 10px;
}
.btn1 {
  margin: 0.3rem;
}
.footDiv {
  width: 100%;
  margin-top: -27px;
  z-index: 99;
}
.outLine {
  color: #3c6ef0;
  border-color: #3c6ef0;
  height: 40px;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}

.position-relative {
  height: 384px;
  overflow: auto;
}
.card {
  // height: 69vh !important;
  border: none;
}
.card-Body {
  // padding-left: 37px;
  position: absolute;
  top: 62px !important;
}
.cdHead {
  height: 60vh !important;
  border: none;
}
.btnSelectScanDir {
  width: 35px;
  height: 29px;
  margin-left: -90px;
  margin-top: 3px;
}
.btnSelectProDir {
  width: 35px;
  height: 29px;
  margin-left: -38px;
  margin-top: 3px;
}
</style>
